//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  getUserInfo:function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function (loginCode) {
         that.globalData.code = loginCode.code;
          wx.getUserInfo({
            success: function (res2) {
              that.globalData.userInfo = res2.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
              that.globalData.encryptedData = encodeURIComponent(res2.encryptedData);//一定要把加密串转成URI编码
              that.globalData.iv = res2.iv;
              console.log(res2);
            }
          })
           wx.getLocation({
            success: function (res) {
               that.globalData.latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                that.globalData.longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                 console.log('纬度'+res.latitude+'经度'+res.longitude);
            },
            cancel: function (res) {
                console.log('用户拒绝授权获取地理位置');
            }
        });
        }
      })
    }
  },
  globalData:{
    userInfo:null,
    code:'',
    encryptedData:'',
    iv:'',
    latitude:'',
    longitude:'',
  }
})